﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using Document_Management.tianche;
namespace Document_Management
{   
   
    public partial class frmDocMnt : Form
    {
     
        static string connectionString = ConfigurationManager.ConnectionStrings["庫存管理"].ConnectionString;
        int width, height;
        int iflag = 0;
        string str = null;
        bool b文件Search, b文件Insert, b文件Edit, b文件Del;
        public frmDocMnt(bool b文件Search, bool b文件Insert, bool b文件Edit, bool b文件Del)
        {
            InitializeComponent();
            this.b文件Search = b文件Search;
            this.b文件Insert = b文件Insert;
            this.b文件Edit = b文件Edit;
            this.b文件Del = b文件Del;
        }

        
        public void resetText_DocUser()
        {
            txtDocUserID.Text="";
            txtDocUserName.Text="";
            txtDocUserNote.Text="";
        }

        public void resetText_DocDesigner()
        {
            txtDocDsID.Text = "";
            txtDocDsName.Text = "";
            txtDocDsNote.Text = "";
        }
        public void resetText_DocDp()
        {
            txtDocDpID.Text = "";
            txtDocDpName.Text = "";
            txtDocDpNote.Text = "";
        }
        public void resetText_DocType()
        {
            txtDocTypeID.Text = "";
            txtDocTypeName.Text = "";
            txtDocTypeNote.Text = "";
        }
        public void resetText_Doc()
        {
            txtDocID1.Text = "";
            txtDocName1.Text = "";
            txtDocVersion1.Text = "";
            txtDocDp1.Text = "";
            txtDocType1.Text = "";
            txtDocUser1.Text = "";
            txtDocDesigner1.Text = "";
        }
        public void resetText_Doc2()
        {
            txtDocID.Text = "";
            txtDocName.Text = "";
            txtDocVersion.Text = "";
            txtDocDp.Text = "";
            txtDocType.Text = "";
            txtDocUser.Text = "";
            txtDocDesigner.Text = "";
        }
        private void frmDocMnt_Load(object sender, EventArgs e)
        {
            Loadall();
            Loadall1();
            Loadall2();
            Loadall3();
            Loadall4();
            resetText_DocUser();
            resetText_DocDesigner();
            resetText_DocDp();
            resetText_DocType();
            resetText_Doc();
            width = this.Size.Width;
            height = this.Size.Height;
            grbhinde.Visible = false;
            this.Size = new System.Drawing.Size(this.Size.Width, this.Size.Height - grbhinde.Height);
            this.DesktopLocation = new Point(0, 0);
        }

        private void Loadall1()
        {
            SqlConnection Con = new SqlConnection(connectionString);
            string sql = "Select * from 文件借用人";
            SqlDataAdapter ad = new SqlDataAdapter(sql, Con);
            DataTable dt = new DataTable();
            ad.Fill(dt);
            dtgDocUser.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dtgDocUser.DataSource = dt;
            PublicClass.setRowNumber(dtgDocUser);
        }
        public void Loadall2()
        {
            SqlConnection Con = new SqlConnection(connectionString);
            string sql = "Select * from 文件建檔人";
            SqlDataAdapter ad = new SqlDataAdapter(sql, Con);
            DataTable dt = new DataTable();
            ad.Fill(dt);
            dtgDocDs.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dtgDocDs.DataSource = dt;
            PublicClass.setRowNumber(dtgDocDs);
        }
        public void Loadall3()
        {
            SqlConnection Con = new SqlConnection(connectionString);
            string sql = "Select * from 文件課別";
            SqlDataAdapter ad = new SqlDataAdapter(sql, Con);
            DataTable dt = new DataTable();
            ad.Fill(dt);
            dtgDocDp.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dtgDocDp.DataSource = dt;
            PublicClass.setRowNumber(dtgDocDp);
        }
        public void Loadall4()
        {
            SqlConnection Con = new SqlConnection(connectionString);
            string sql = "Select * from 文件類別";
            SqlDataAdapter ad = new SqlDataAdapter(sql, Con);
            DataTable dt = new DataTable();
            ad.Fill(dt);
            dtgDocType.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dtgDocType.DataSource = dt;
            PublicClass.setRowNumber(dtgDocType);
        }
        public void Loadall()
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                string sql = "select 文件.編號,文件.課別代號,文件.文件類別代號,文件.版次,文件.附件路徑,文件.建檔人代號,文件.借用人代號 from 文件 inner join 文件課別 on 文件.課別代號=文件課別.課別代號 inner join 文件類別 on 文件.文件類別代號=文件類別.文件類別代號 inner join 文件建檔人 on 文件.建檔人代號=文件建檔人.建檔人代號 inner join 文件借用人 on 文件.借用人代號=文件借用人.借用人代號";
                SqlDataAdapter da = new SqlDataAdapter(sql,con);
                DataTable dt = new DataTable();
                da.Fill(dt);
                dtgDoc.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                dtgDoc.DataSource = dt;
                PublicClass.setRowNumber(dtgDoc);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
        }

        private void btnaddproduct_Click(object sender, EventArgs e)
        {
            iflag = 1;
            btnaddnewupdatedelete.Text = "入庫";
            this.Size = new System.Drawing.Size(width, height);
            grbhinde.Visible = true;
        }

        private void btnEditproduct_Click(object sender, EventArgs e)
        {
            iflag = 2;
            btnaddnewupdatedelete.Text = "更新";
            this.Size = new System.Drawing.Size(width, height);
            grbhinde.Visible = true;
        }

        private void btndelete_Click(object sender, EventArgs e)
        {
            iflag = 3;
            btnaddnewupdatedelete.Text = "確認";
            this.Size = new System.Drawing.Size(width, height);
            grbhinde.Visible = true;
           
        }

        private void btnhide_Click(object sender, EventArgs e)
        {
            grbhinde.Visible = false;
            this.Size = new Size(width, height - grbhinde.Height);
        }

        public void hidel()
        {
            grbhinde.Visible = false;
            this.Size = new Size(width, height - grbhinde.Height);
        }

        private void btnaddnewupdatedelete_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            if (iflag == 1) //insert
            {
                try
                {
                    if (txtDocID1.Text == "")
                    {
                        MessageBox.Show("請您輸入文件代號", "錯誤", MessageBoxButtons.OK);
                        txtDocID.Focus();
                        return;
                    }

                    if (txtDocDp1.Text=="")
                    {
                        MessageBox.Show("請您輸入文件課別", "錯誤", MessageBoxButtons.OK);
                        txtDocDp1.Focus();
                        return;
                    }
                    if (txtDocType1.Text == "")
                    {
                        MessageBox.Show("請您輸入文件類別", "錯誤", MessageBoxButtons.OK);
                        txtDocType1.Focus();
                        return;
                    }
                    if (txtDocVersion1.Text == "")
                    {
                        MessageBox.Show("請您輸入文件版次", "錯誤", MessageBoxButtons.OK);
                        txtDocVersion1.Focus();
                        return;
                    }
                    if (txtDocDesigner1.Text == "")
                    {
                        MessageBox.Show("請您輸入文件建檔人", "錯誤", MessageBoxButtons.OK);
                        txtDocDesigner1.Focus();
                        return;
                    }
                    if (txtDocUser1.Text == "")
                    {
                        MessageBox.Show("請您輸入文件借用人", "錯誤", MessageBoxButtons.OK);
                        txtDocUser1.Focus();
                        return;
                    }
                    con.Open();
                    string sp_insert = "sp_文件_新增";
                    SqlCommand cmd = new SqlCommand(sp_insert, con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@編號", txtDocID1.Text);
                    cmd.Parameters.AddWithValue("@課別代號", txtDocDp1.Text);
                    cmd.Parameters.AddWithValue("@文件類別代號", txtDocType1.Text);
                    cmd.Parameters.AddWithValue("@版次", txtDocVersion1.Text);
                    cmd.Parameters.AddWithValue("@附件路徑", txtDocName1.Text);
                    cmd.Parameters.AddWithValue("@建檔人代號", txtDocDesigner1.Text);
                    cmd.Parameters.AddWithValue("@借用人代號", txtDocUser1.Text);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("新增成功");
                    Loadall();
                    //reset all text
                    txtDocID1.ResetText();
                    txtDocVersion1.ResetText();
                    txtDocName1.ResetText();
                    txtDocDp1.ResetText();
                    txtDocType1.ResetText();
                    txtDocDesigner1.ResetText();
                    txtDocUser1.ResetText();
                    hidel();
                    con.Close();
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            if (iflag == 2) //update
            {
                try
                {
                    con.Open();
                    SqlCommand cmd;
                    String sql = "SELECT COUNT(*) FROM 文件 WHERE 編號=N'" + str + "'";
                    cmd = new SqlCommand(sql, con);
                    if ((int)cmd.ExecuteScalar() > 0)
                    {
                        string sp_update = "sp_文件_更新";
                        cmd = new SqlCommand(sp_update, con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        //con.Open();
                        cmd.Parameters.AddWithValue("@編號", str);
                        cmd.Parameters.AddWithValue("@編號2", txtDocID1.Text);
                        cmd.Parameters.AddWithValue("@課別代號", txtDocDp1.Text);
                        cmd.Parameters.AddWithValue("@文件類別代號", txtDocType1.Text);
                        cmd.Parameters.AddWithValue("@版次", txtDocVersion1.Text);
                        cmd.Parameters.AddWithValue("@附件路徑", txtDocName1.Text);
                        cmd.Parameters.AddWithValue("@建檔人代號", txtDocDesigner1.Text);
                        cmd.Parameters.AddWithValue("@借用人代號", txtDocUser1.Text);

                        cmd.ExecuteNonQuery();
                        MessageBox.Show("更新成功");
                        Loadall();
                        
                        //reset all text
                        txtDocID1.ResetText();
                        txtDocVersion1.ResetText();
                        txtDocName1.ResetText();
                        txtDocDp1.ResetText();
                        txtDocType1.ResetText();
                        txtDocDesigner1.ResetText();
                        txtDocUser1.ResetText();
                        hidel();
                        con.Close();
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Error! '" + txtDocID1.Text.ToString() + "' 不由來");
                        con.Close();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            if (iflag == 3) //delete
            {
                try
                {
                    con.Open();
                    DialogResult answer = MessageBox.Show("您確定要出入這個文件？", "警報", MessageBoxButtons.YesNo);
                    if (answer == DialogResult.Yes)
                    {
                        string sp_delete = "delete from 文件 where 編號 = '" + txtDocID1.Text + "'";
                        SqlCommand sqldelete = new SqlCommand();
                        sqldelete.Connection = con;
                        sqldelete.CommandText = sp_delete;
                        sqldelete.ExecuteNonQuery();
                        MessageBox.Show("刪除成功");
                        Loadall();
                        //reset all text
                        txtDocID1.ResetText();
                        txtDocVersion1.ResetText();
                        txtDocName1.ResetText();
                        txtDocDp1.ResetText();
                        txtDocType1.ResetText();
                        txtDocDesigner1.ResetText();
                        txtDocUser1.ResetText();
                        hidel();
                        return;
                    }
                    else
                    {
                        Loadall();
                        return;
                    }
                    con.Close();

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void dtgDoc_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                str = dtgDoc.Rows[i].Cells[0].Value.ToString();
                txtDocID1.Text = dtgDoc.Rows[i].Cells[0].Value.ToString();
                txtDocDp1.Text = dtgDoc.Rows[i].Cells[1].Value.ToString();
                txtDocType1.Text = dtgDoc.Rows[i].Cells[2].Value.ToString();
                txtDocVersion1.Text = dtgDoc.Rows[i].Cells[3].Value.ToString();
                txtDocName1.Text = dtgDoc.Rows[i].Cells[4].Value.ToString();
                txtDocDesigner1.Text = dtgDoc.Rows[i].Cells[5].Value.ToString();
                txtDocUser1.Text = dtgDoc.Rows[i].Cells[6].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            grbhinde.Visible = false;
            this.Size = new Size(width, height - grbhinde.Height);
            PublicClass.setRowNumber(dtgDocUser);
            PublicClass.setRowNumber(dtgDoc);
            PublicClass.setRowNumber(dtgDocType);
            PublicClass.setRowNumber(dtgDocDp);
            PublicClass.setRowNumber(dtgDocDs);
            resetText_DocUser();
            resetText_DocDesigner();
            resetText_DocDp();
            resetText_DocType();
            resetText_Doc();
        }

        private void btnDocUserClean_Click(object sender, EventArgs e)
        {
            txtDocUserID.Text = "";
            txtDocUserName.Text = "";
            txtDocUserNote.Text = "";
        }

        private void btnDocDsClean_Click(object sender, EventArgs e)
        {
            txtDocDsID.Text = "";
            txtDocDsName.Text = "";
            txtDocDsNote.Text = "";
        }

        private void dtgDocUser_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                str = dtgDocUser.Rows[i].Cells[0].Value.ToString();
                txtDocUserID.Text = dtgDocUser.Rows[i].Cells[0].Value.ToString();
                txtDocUserName.Text = dtgDocUser.Rows[i].Cells[1].Value.ToString();
                txtDocUserNote.Text = dtgDocUser.Rows[i].Cells[2].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dtgDocDs_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                str = dtgDocDs.Rows[i].Cells[0].Value.ToString();
                txtDocDsID.Text = dtgDocDs.Rows[i].Cells[0].Value.ToString();
                txtDocDsName.Text = dtgDocDs.Rows[i].Cells[1].Value.ToString();
                txtDocDsNote.Text = dtgDocDs.Rows[i].Cells[2].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnDocUserAdd_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {

                if (txtDocUserID.Text == "")
                {
                    MessageBox.Show("請您輸入借用人代號", "錯誤", MessageBoxButtons.OK);
                    txtDocUserID.Focus();
                    return;
                }

                if (txtDocUserName.Text == "")
                {
                    MessageBox.Show("請您輸入借用人姓名", "錯誤", MessageBoxButtons.OK);
                    txtDocUserName.Focus();
                    return;
                }
                con.Open();
                string sp_insert = "sp_文件借用人_新增";
                SqlCommand cmd = new SqlCommand(sp_insert, con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@借用人代號", txtDocUserID.Text);
                cmd.Parameters.AddWithValue("@姓名", txtDocUserName.Text);
                cmd.Parameters.AddWithValue("@備註", txtDocUserNote.Text.ToString());
                cmd.ExecuteNonQuery();
                MessageBox.Show("新增成功","訊息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                Loadall1();
                //reset all text
                txtDocUserID.ResetText();
                txtDocUserName.ResetText();
                txtDocUserNote.ResetText();
                con.Close();
                return;

            }
            catch (Exception ex)
            {
                con.Close();
                MessageBox.Show(ex.Message);
                return;
            }
        }

        private void btnDocUserEdit_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                SqlCommand cmd;
                String sql = "SELECT COUNT(*) FROM 文件借用人 WHERE 借用人代號=N'" + str + "'";
                cmd = new SqlCommand(sql, con);
                if ((int)cmd.ExecuteScalar() > 0)
                {
                    string sp_update = "sp_文件借用人_更新";
                    cmd = new SqlCommand(sp_update, con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    //con.Open();
                    cmd.Parameters.AddWithValue("@借用人代號", str);
                    cmd.Parameters.AddWithValue("@借用人代號2", txtDocUserID.Text);
                    cmd.Parameters.AddWithValue("@姓名", txtDocUserName.Text);
                    cmd.Parameters.AddWithValue("@備註", txtDocUserNote.Text.ToString());
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("更新成功","訊息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    Loadall1();
                    MessageBox.Show("更新成功");
                    txtDocUserID.ResetText();
                    txtDocUserName.ResetText();
                    txtDocUserNote.ResetText();
                    con.Close();
                    return;
                }
                else
                {
                    MessageBox.Show("Error! '" + txtDocUserID.Text.ToString() + "' 不由來");
                    con.Close();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Loadall1();
                con.Close();
                return;
            }
        }

        private void btnDocUserDelete_Click(object sender, EventArgs e)
        {
           
            try
            {
                SqlConnection con = new SqlConnection(connectionString);
                con.Open();
                DialogResult answer = MessageBox.Show("您確定要出入這個借用人", "警報", MessageBoxButtons.YesNo);
                if (answer == DialogResult.Yes)
                {
                    string sp_delete = "delete from 文件借用人 where 借用人代號 = '" + txtDocUserID.Text + "'";
                    SqlCommand sqldelete = new SqlCommand();
                    sqldelete.Connection = con;
                    sqldelete.CommandText = sp_delete;
                    sqldelete.ExecuteNonQuery();
                    MessageBox.Show("刪除成功","訊息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    Loadall1();
                    txtDocUserID.ResetText();
                    txtDocUserName.ResetText();
                    txtDocUserNote.ResetText();
                    return;
                }
                else
                {
                    Loadall1();
                    return;
                }
                con.Close();

            }
            catch (Exception ex)
            {
               
                MessageBox.Show(ex.Message);
                return;
            }
        }

        private void btnDocDsAdd_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {

                if (txtDocDsID.Text == "")
                {
                    MessageBox.Show("請您輸入材編", "錯誤", MessageBoxButtons.OK);
                    txtDocDsID.Focus();
                    return;
                }

                if (txtDocDsName.Text == "")
                {
                    MessageBox.Show("請您輸入品名", "錯誤", MessageBoxButtons.OK);
                    txtDocDsName.Focus();
                    return;
                }
                con.Open();
                string sp_insert = "sp_文件建檔人_新增";
                SqlCommand cmd = new SqlCommand(sp_insert, con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@建檔人代號", txtDocDsID.Text);
                cmd.Parameters.AddWithValue("@姓名", txtDocDsName.Text);
                cmd.Parameters.AddWithValue("@備註", txtDocDsNote.Text.ToString());
                cmd.ExecuteNonQuery();
                MessageBox.Show("新增成功","訊息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                Loadall2();
                //reset all text
                txtDocDsID.ResetText();
                txtDocDsName.ResetText();
                txtDocDsNote.ResetText();
                con.Close();
                return;

            }
            catch (Exception ex)
            {
                con.Close();
                MessageBox.Show(ex.Message);
                return;
            }
        }

        private void btnDocDsEdit_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                SqlCommand cmd;
                String sql = "SELECT COUNT(*) FROM 文件建檔人 WHERE 建檔人代號=N'" + str + "'";
                cmd = new SqlCommand(sql, con);
                if ((int)cmd.ExecuteScalar() > 0)
                {
                    string sp_update = "sp_文件建檔人_更新";
                    cmd = new SqlCommand(sp_update, con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    //con.Open();
                    cmd.Parameters.AddWithValue("@建檔人代號", str);
                    cmd.Parameters.AddWithValue("@建檔人代號2", txtDocDsID.Text);
                    cmd.Parameters.AddWithValue("@姓名", txtDocDsName.Text);
                    cmd.Parameters.AddWithValue("@備註", txtDocDsNote.Text.ToString());
                    MessageBox.Show("更新成功","訊息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    cmd.ExecuteNonQuery();
                    Loadall2();
                    MessageBox.Show("更新成功");
                    txtDocDsID.ResetText();
                    txtDocDsName.ResetText();
                    txtDocDsNote.ResetText();
                    con.Close();
                    return;
                }
                else
                {
                    MessageBox.Show("Error! '" + txtDocDsID.Text.ToString() + "' 不由來");
                    con.Close();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Loadall2();
                con.Close();
                return;
            }
        }

        private void btnDocDsDelete_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                DialogResult answer = MessageBox.Show("您確定要出入這個建檔人代號", "警報", MessageBoxButtons.YesNo);
                if (answer == DialogResult.Yes)
                {
                    string sp_delete = "delete from 文件建檔人 where 建檔人代號 = '" + txtDocDsID.Text + "'";
                    SqlCommand sqldelete = new SqlCommand();
                    sqldelete.Connection = con;
                    sqldelete.CommandText = sp_delete;
                    sqldelete.ExecuteNonQuery();
                    MessageBox.Show("刪除成功","訊息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    Loadall2();
                    txtDocDsID.ResetText();
                    txtDocDsName.ResetText();
                    txtDocDsNote.ResetText();
                    return;
                }
                else
                {
                    Loadall2();
                    return;
                }
                con.Close();

            }
            catch (Exception ex)
            {
                con.Close();
                MessageBox.Show(ex.ToString());
                return;
            }
        }
        //tabDocDp
        private void dtgDocDp_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                str = dtgDocDp.Rows[i].Cells[0].Value.ToString();
                txtDocDpID.Text = dtgDocDp.Rows[i].Cells[0].Value.ToString();
                txtDocDpName.Text = dtgDocDp.Rows[i].Cells[1].Value.ToString();
                txtDocDpNote.Text = dtgDocDp.Rows[i].Cells[2].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnDocDpClean_Click(object sender, EventArgs e)
        {
            txtDocDpID.Text = "";
            txtDocDpName.Text = "";
            txtDocDpNote.Text = "";
        }

        private void btnDocDpAdd_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {

                if (txtDocDpID.Text == "")
                {
                    MessageBox.Show("請您輸入課別代號", "錯誤", MessageBoxButtons.OK);
                    txtDocDpID.Focus();
                    return;
                }

                if (txtDocDpName.Text == "")
                {
                    MessageBox.Show("請您輸入課別名稱", "錯誤", MessageBoxButtons.OK);
                    txtDocDpName.Focus();
                    return;
                }
                con.Open();
                string sp_insert = "sp_文件課別_新增";
                SqlCommand cmd = new SqlCommand(sp_insert, con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@課別代號", txtDocDpID.Text);
                cmd.Parameters.AddWithValue("@名稱", txtDocDpName.Text);
                cmd.Parameters.AddWithValue("@備註", txtDocDpNote.Text.ToString());
                cmd.ExecuteNonQuery();
                MessageBox.Show("新增成功","訊息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                Loadall3();
                //reset all text
                txtDocDpID.ResetText();
                txtDocDpName.ResetText();
                txtDocDpNote.ResetText();
                con.Close();
                return;

            }
            catch (Exception ex)
            {
                con.Close();
                MessageBox.Show(ex.Message);
                return;
            }
        }

        private void btnDocDpEdit_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                SqlCommand cmd;
                String sql = "SELECT COUNT(*) FROM 文件課別 WHERE 課別代號=N'" + str + "'";
                cmd = new SqlCommand(sql, con);
                if ((int)cmd.ExecuteScalar() > 0)
                {
                    string sp_update = "sp_文件課別_更新";
                    cmd = new SqlCommand(sp_update, con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    //con.Open();
                    cmd.Parameters.AddWithValue("@課別代號", str);
                    cmd.Parameters.AddWithValue("@課別代號2", txtDocDpID.Text);
                    cmd.Parameters.AddWithValue("@名稱", txtDocDpName.Text);
                    cmd.Parameters.AddWithValue("@備註", txtDocDpNote.Text.ToString());
                    MessageBox.Show("更新成功","訊息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    cmd.ExecuteNonQuery();
                    Loadall3();
                    MessageBox.Show("更新成功");
                    txtDocDpID.ResetText();
                    txtDocDpName.ResetText();
                    txtDocDpNote.ResetText();
                    con.Close();
                    return;
                }
                else
                {
                    MessageBox.Show("Error! '" + txtDocDpID.Text.ToString() + "' 不由來");
                    con.Close();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Loadall3();
                con.Close();
                return;
            }
        }

        private void btnDocDpDelete_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                DialogResult answer = MessageBox.Show("您確定要出入這個課別？", "警報", MessageBoxButtons.YesNo);
                if (answer == DialogResult.Yes)
                {
                    string sp_delete = "delete from 文件課別 where 課別代號 = '" + txtDocDpID.Text + "'";
                    SqlCommand sqldelete = new SqlCommand();
                    sqldelete.Connection = con;
                    sqldelete.CommandText = sp_delete;
                    MessageBox.Show("刪除成功");
                    sqldelete.ExecuteNonQuery();
                    Loadall3();
                    txtDocDpID.ResetText();
                    txtDocDpName.ResetText();
                    txtDocDpNote.ResetText();
                    return;
                }
                else
                {
                    Loadall3();
                    return;
                }
                con.Close();

            }
            catch (Exception ex)
            {
                con.Close();
                MessageBox.Show(ex.ToString());
                return;
            }
        }

        private void dtgDocType_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int i = e.RowIndex;
                str = dtgDocType.Rows[i].Cells[0].Value.ToString();
                txtDocTypeID.Text = dtgDocType.Rows[i].Cells[0].Value.ToString();
                txtDocTypeName.Text = dtgDocType.Rows[i].Cells[1].Value.ToString();
                txtDocTypeNote.Text = dtgDocType.Rows[i].Cells[2].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnDocTypeClean_Click(object sender, EventArgs e)
        {
            txtDocTypeID.Text = "";
            txtDocTypeName.Text = "";
            txtDocTypeNote.Text = "";
        }

        private void btnDocTypeAdd_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {

                if (txtDocTypeID.Text == "")
                {
                    MessageBox.Show("請您輸入文件類別代號", "錯誤", MessageBoxButtons.OK);
                    txtDocTypeID.Focus();
                    return;
                }

                if (txtDocTypeName.Text == "")
                {
                    MessageBox.Show("請您輸入文件類別名稱", "錯誤", MessageBoxButtons.OK);
                    txtDocTypeName.Focus();
                    return;
                }
                con.Open();
                string sp_insert = "sp_文件類別_新增";
                SqlCommand cmd = new SqlCommand(sp_insert, con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@文件類別代號", txtDocTypeID.Text);
                cmd.Parameters.AddWithValue("@名稱", txtDocTypeName.Text);
                cmd.Parameters.AddWithValue("@備註", txtDocTypeNote.Text.ToString());
                cmd.ExecuteNonQuery();
                MessageBox.Show("新增成功","訊息",MessageBoxButtons.OK,MessageBoxIcon.Information);
                Loadall4();
                //reset all text
                txtDocTypeID.ResetText();
                txtDocTypeName.ResetText();
                txtDocTypeNote.ResetText();
                con.Close();
                return;

            }
            catch (Exception ex)
            {
                con.Close();
                MessageBox.Show(ex.Message);
                return;
            }
        }

        private void btnDocTypeEdit_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                SqlCommand cmd;
                String sql = "SELECT COUNT(*) FROM 文件類別 WHERE 文件類別代號=N'" + str + "'";
                cmd = new SqlCommand(sql, con);
                if ((int)cmd.ExecuteScalar() > 0)
                {
                    string sp_update = "sp_文件類別_更新";
                    cmd = new SqlCommand(sp_update, con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    //con.Open();
                    cmd.Parameters.AddWithValue("@文件類別代號", str);
                    cmd.Parameters.AddWithValue("@文件類別代號2", txtDocTypeID.Text);
                    cmd.Parameters.AddWithValue("@名稱", txtDocTypeName.Text);
                    cmd.Parameters.AddWithValue("@備註", txtDocTypeNote.Text.ToString());

                    cmd.ExecuteNonQuery();
                    Loadall4();
                    MessageBox.Show("更新成功");
                    txtDocTypeID.ResetText();
                    txtDocTypeName.ResetText();
                    txtDocTypeNote.ResetText();
                    con.Close();
                    return;
                }
                else
                {
                    MessageBox.Show("Error! '" + txtDocTypeID.Text.ToString() + "' 不由來");
                    con.Close();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Loadall4();
                con.Close();
                return;
            }
        }

        private void btnDocTypeDelete_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                DialogResult answer = MessageBox.Show("您確定要出入這個文件類別", "警報", MessageBoxButtons.YesNo);
                if (answer == DialogResult.Yes)
                {
                    string sp_delete = "delete from 文件類別 where 文件類別代號 = '" + txtDocTypeID.Text + "'";
                    SqlCommand sqldelete = new SqlCommand();
                    sqldelete.Connection = con;
                    sqldelete.CommandText = sp_delete;
                    MessageBox.Show("刪除成功");
                    sqldelete.ExecuteNonQuery();
                    Loadall4();
                    txtDocTypeID.ResetText();
                    txtDocTypeName.ResetText();
                    txtDocTypeNote.ResetText();
                    return;
                }
                else
                {
                    Loadall4();
                    return;
                }
                con.Close();

            }
            catch (Exception ex)
            {
                con.Close();
                MessageBox.Show(ex.ToString());
                return;
            }
        }

        private void btnDocSearch_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {

                con.Open();

                string sp = "sp_文件_尋找";
                SqlCommand cmd = new SqlCommand(sp, con);
                cmd.CommandType = CommandType.StoredProcedure;
                if (txtDocID.Text != "") cmd.Parameters.AddWithValue("@編號", txtDocID.Text);
                if (txtDocDp.Text != "") cmd.Parameters.AddWithValue("@課別代號", txtDocDp.Text);
                if (txtDocType.Text != "") cmd.Parameters.AddWithValue("@文件類別代號", txtDocType.Text);
                if (txtDocVersion.Text != "") cmd.Parameters.AddWithValue("@版次", txtDocVersion.Text);
                if (txtDocName.Text != "") cmd.Parameters.AddWithValue("@附件路徑", txtDocName.Text);
                if (txtDocDesigner.Text != "") cmd.Parameters.AddWithValue("@建檔人代號", txtDocDesigner.Text);
                if (txtDocUser.Text != "") cmd.Parameters.AddWithValue("@借用人代號", txtDocUser.Text);
                SqlDataReader sqlreader = cmd.ExecuteReader();
                DataTable dt = new DataTable();
                //dt.Columns.Add("項次");//add new 項次 column
                dt.Columns.Add("編號");
                dt.Columns.Add("課別代號");
                dt.Columns.Add("文件類別代號");
                dt.Columns.Add("版次");
                dt.Columns.Add("附件路徑");
                dt.Columns.Add("建檔人代號");
                dt.Columns.Add("借用人代號");
                //int k=1;
                while (sqlreader.Read())
                {
                    DataRow dtrows = dt.NewRow();
                    //dtrows["項次"]=k.ToString();
                    dtrows["編號"] = sqlreader["編號"];
                    dtrows["課別代號"] = sqlreader["課別代號"];
                    dtrows["文件類別代號"] = sqlreader["文件類別代號"];
                    dtrows["版次"] = sqlreader["版次"];
                    dtrows["附件路徑"] = sqlreader["附件路徑"];
                    dtrows["建檔人代號"] = sqlreader["建檔人代號"];
                    dtrows["借用人代號"] = sqlreader["借用人代號"];
                    dt.Rows.Add(dtrows);
                    //k++;
                }

                //change column width
                //dataGridview庫存.Columns[0].Width = 30;
                dtgDoc.DataSource = dt;
                PublicClass.setRowNumber(dtgDoc);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
        }

        private void btnDocDpFind_Click(object sender, EventArgs e)
        {
            frmSearchDp frm = new frmSearchDp(txtDocDp1);
            frm.Show();
        }

        private void btnDocTypeFind_Click(object sender, EventArgs e)
        {
            frmSearchType frm = new frmSearchType(txtDocType1);
            frm.Show();
        }

        private void btnDocDsFind_Click(object sender, EventArgs e)
        {
            frmSearchDesigner frm = new frmSearchDesigner(txtDocDesigner1);
            frm.Show();
        }

        private void btnDocUserFind_Click(object sender, EventArgs e)
        {
            frmSearchUser frm = new frmSearchUser(txtDocUser1);
            frm.Show();
        }

        private void dtgDoc_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgDoc);
        }

        private void dtgDoc_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgDoc);
        }

        private void dtgDocUser_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgDocUser);
        }

        private void dtgDocUser_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgDocUser);
        }

        private void dtgDocDs_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgDocDs);
        }

        private void dtgDocDs_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgDocDs);
        }

        private void dtgDocDp_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgDocDp);
        }

        private void dtgDocDp_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgDocDp);
        }

        private void dtgDocType_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgDocType);
        }

        private void dtgDocType_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgDocType);
        }

        private void btnUrl_Click(object sender, EventArgs e)
        {
            string Rrl = "";
            string Rrl2 = "";
            string temp = "";
            string temp2 = "";
            string fileName;
            string path = "";
            string fileToCopy = "";
            OpenFileDialog fDialog = new OpenFileDialog();
            fDialog.Title = "開啟檔案(Attach customer proposal document)";
            //fDialog.Filter = "Doc Files|*.doc|Docx File|*.docx|PDF doc|*.pdf";
            fDialog.Filter = "檔案當 (*.txt, *.doc, *.docx, *.xls, *.xlsx, *.ppt, *.pptx, *.pdf) | *.txt; *.doc; *.docx; *.xlsx;*.xls; *.ppt; *.pptx; *.pdf | All Files|*.*";
            fDialog.InitialDirectory = Application.StartupPath + @"Documents\\";
            if (fDialog.ShowDialog() == DialogResult.OK)
            {
                fileName = System.IO.Path.GetFileName(fDialog.FileName);
                path = Path.GetDirectoryName(fDialog.FileName);
                txtDocName1.Text = path + "\\" + fileName;
                //copyfile(); 
                try
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml("C:\\config\\config文件.xml");
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        temp += dr["UrlServer"].ToString() + "\n";
                        temp2 += dr["UrlClient"].ToString() + "\n";
                    }
                    temp = temp.Substring(0, temp.Length - 1);
                    temp2 = temp2.Substring(0, temp2.Length - 1);
                    Rrl = temp;
                    Rrl2 = temp2;
                    //==================================================
                    //string destinationDirectory = @"C:\workspace\";
                    string destinationDirectory = @"" + Rrl + "";
                    fileToCopy = txtDocName1.Text;
                    File.Copy(fileToCopy, destinationDirectory + Path.GetFileName(fileToCopy), true);
                    txtDocName1.Text = destinationDirectory + "\\" + fileName;
                }
                catch(Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private void dtgDoc_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string Rrl = "";
            string Rrl2 = "";
            string temp = "";
            //string temp2 = "";
            try
            {
                DialogResult result = new DialogResult();
                PublicClass.setRowNumber(dtgDoc);
                if (dtgDoc.CurrentCell.ColumnIndex.Equals(4))
                {
                    if (dtgDoc.CurrentCell != null && dtgDoc.CurrentCell.Value != null)
                    //MessageBox.Show(dataGridstockvehicles.CurrentCell.Value.ToString(), "Save", );
                    {
                        string rooturl = dtgDoc.CurrentCell.Value.ToString();
                        result = MessageBox.Show("你要不要存檔這個資料？" + "\n" + rooturl, "存檔圖面", MessageBoxButtons.YesNo);
                        if (result == DialogResult.Yes)
                        {
                            FolderBrowserDialog fDialogSave = new FolderBrowserDialog();
                            if (fDialogSave.ShowDialog() == DialogResult.OK)
                            {
                                string foldername = fDialogSave.SelectedPath;
                                DataSet ds = new DataSet();
                                ds.ReadXml("C:\\config\\config文件.xml");
                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    temp += dr["UrlServer"].ToString() + "\n";
                                    //temp2 += dr["UrlClient"].ToString() + "\n";
                                }
                                temp = temp.Substring(0, temp.Length - 1);
                                //filename = temp2.Substring(0, filename.Length - 1);
                                Rrl = temp;
                                Rrl = Rrl + Path.GetFileName(dtgDoc.CurrentCell.Value.ToString());
                                //Rrl2 = temp2;
                                Rrl2 = foldername + "\\" + Path.GetFileName(dtgDoc.CurrentCell.Value.ToString());
                                File.Copy(Rrl, Rrl2, true);
                                MessageBox.Show("另存為成功","");
                                //Loadall();
                                return;
                            }
                        }
                        else if (result == DialogResult.No)
                        {
                            //MessageBox.Show("還沒成功");
                            Loadall();
                            return;
                        }


                        ////Savefile(); 
                        //result = MessageBox.Show("你要不要存檔這個資料？" + "\n" + dtgDoc.CurrentCell.Value.ToString(), "Save", MessageBoxButtons.YesNo);
                        //if (result == DialogResult.Yes)
                        //{
                        //    //Savefile(); 
                        //    try
                        //    {
                        //        DataSet ds = new DataSet();
                        //        ds.ReadXml("C:\\config\\config文件.xml");
                        //        foreach (DataRow dr in ds.Tables[0].Rows)
                        //        {
                        //            temp += dr["UrlServer"].ToString() + "\n";
                        //            temp2 += dr["UrlClient"].ToString() + "\n";
                        //        }
                        //        temp = temp.Substring(0, temp.Length - 1);
                        //        temp2 = temp2.Substring(0, temp2.Length - 1);
                        //        Rrl = temp;
                        //        Rrl2 = temp2;
                        //        string destinationDirectory = @"" + temp2 + "";
                        //        File.Copy(dtgDoc.CurrentCell.Value.ToString(), destinationDirectory + Path.GetFileName(dtgDoc.CurrentCell.Value.ToString()), true);
                        //        MessageBox.Show("存档成功");
                        //    }
                        //    catch { }
                        //}
                        //else if (result == DialogResult.No)
                        //{
                        //    //MessageBox.Show("還沒成功");
                        //}
                    }
                }
            }
            catch { }

        }

        private void txtDocDp1_TextChanged(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                String temp = "";
                string strcmd = String.Format("select * from 文件課別 where 課別代號=N'{0}'", txtDocDp1.Text);
                SqlCommand cmd = new SqlCommand(strcmd, con);
                var x = cmd.ExecuteReader();
                //int icount=0;
                while (x.Read()) temp = x[1].ToString();
                if (temp == "") lbName課別.Text = "";
                else lbName課別.Text = temp;
            }
            catch (Exception ex) { }
        }

        private void txtDocType1_TextChanged(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                String temp = "";
                string strcmd = String.Format("select * from 文件類別 where 文件類別代號=N'{0}'", txtDocType1.Text);
                SqlCommand cmd = new SqlCommand(strcmd, con);
                var x = cmd.ExecuteReader();
                //int icount=0;
                while (x.Read()) temp = x[1].ToString();
                if (temp == "") lbName文件類型.Text = "";
                else lbName文件類型.Text = temp;
            }
            catch (Exception ex) { }
        }

        private void txtDocDesigner1_TextChanged(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                String temp = "";
                string strcmd = String.Format("select * from 文件建檔人 where 建檔人代號=N'{0}'", txtDocDesigner1.Text);
                SqlCommand cmd = new SqlCommand(strcmd, con);
                var x = cmd.ExecuteReader();
                //int icount=0;
                while (x.Read()) temp = x[1].ToString();
                if (temp == "") lbName建檔人.Text = "";
                else lbName建檔人.Text = temp;
            }
            catch (Exception ex) { }
        }

        private void txtDocUser1_TextChanged(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                String temp = "";
                string strcmd = String.Format("select * from 文件借用人 where 借用人代號=N'{0}'", txtDocUser1.Text);
                SqlCommand cmd = new SqlCommand(strcmd, con);
                var x = cmd.ExecuteReader();
                //int icount=0;
                while (x.Read()) temp = x[1].ToString();
                if (temp == "") lbName借用人.Text = "";
                else lbName借用人.Text = temp;
            }
            catch (Exception ex) { }
        }

        private void btnResetAllText圖面_Click(object sender, EventArgs e)
        {
            resetText_Doc2();
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                string sp = "sp_文件_尋找";
                SqlCommand cmd = new SqlCommand(sp, con);
                cmd.CommandType = CommandType.StoredProcedure;
                if (txtDocID.Text != "") cmd.Parameters.AddWithValue("@編號", txtDocID.Text);
                if (txtDocDp.Text != "") cmd.Parameters.AddWithValue("@課別代號", txtDocDp.Text);
                if (txtDocType.Text != "") cmd.Parameters.AddWithValue("@文件類別代號", txtDocType.Text);
                if (txtDocVersion.Text != "") cmd.Parameters.AddWithValue("@版次", txtDocVersion.Text);
                if (txtDocName.Text != "") cmd.Parameters.AddWithValue("@附件路徑", txtDocName.Text);
                if (txtDocDesigner.Text != "") cmd.Parameters.AddWithValue("@建檔人代號", txtDocDesigner.Text);
                if (txtDocUser.Text != "") cmd.Parameters.AddWithValue("@借用人代號", txtDocUser.Text);
                SqlDataReader sqlreader = cmd.ExecuteReader();
                DataTable dt = new DataTable();
                //dt.Columns.Add("項次");//add new 項次 column
                dt.Columns.Add("編號");
                dt.Columns.Add("課別代號");
                dt.Columns.Add("文件類別代號");
                dt.Columns.Add("版次");
                dt.Columns.Add("附件路徑");
                dt.Columns.Add("建檔人代號");
                dt.Columns.Add("借用人代號");
                //int k=1;
                while (sqlreader.Read())
                {
                    DataRow dtrows = dt.NewRow();
                    //dtrows["項次"]=k.ToString();
                    dtrows["編號"] = sqlreader["編號"];
                    dtrows["課別代號"] = sqlreader["課別代號"];
                    dtrows["文件類別代號"] = sqlreader["文件類別代號"];
                    dtrows["版次"] = sqlreader["版次"];
                    dtrows["附件路徑"] = sqlreader["附件路徑"];
                    dtrows["建檔人代號"] = sqlreader["建檔人代號"];
                    dtrows["借用人代號"] = sqlreader["借用人代號"];
                    dt.Rows.Add(dtrows);
                    //k++;
                }

                //change column width
                //dataGridview庫存.Columns[0].Width = 30;
                dtgDoc.DataSource = dt;
                PublicClass.setRowNumber(dtgDoc);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
        }
        
    }
}
